﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.03.22
 * 描 述：车辆管理
 */
var selectedRow;
var refreshGirdData;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGrid();
            page.bind();
        },
        bind: function () {
            // 搜索框初始化
            $('#txt_Keyword').on("keypress", function (e) {
                if (event.keyCode == "13") {
                    var $this = $(this);
                    var keyword = $this.val();
                    page.search({keyword: keyword});
                }
            });
            // 查询
            $('#btn_Search').on('click', function () {
                var keyword = $('#txt_Keyword').val();
                page.search({keyword: keyword});
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 新增
            $('#lr_add').on('click', function () {
                selectedRow = null;
                learun.layerForm({
                    id: 'form',
                    title: '添加车辆档案',
                    url: config.webportal_server + 'pages/system/car/form.html?access_token=' + config.getToken().access_token,
                    width: 900,
                    height: 640,
                    callBack: function (id) {
                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });
            // 编辑
            $('#lr_edit').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('id');
                selectedRow = $('#gridtable').jfGridGet('rowdata');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form',
                        title: '编辑车辆档案',
                        url: config.webportal_server + 'pages/system/car/form.html?access_token=' + config.getToken().access_token,
                        width: 900,
                        height: 640,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });
            // 数据导出
            $('#lr_export').on('click', function () {
                location.href = config.base_server() + 'cars/exportExcel?access_token=' + config.getToken().access_token;
            });
        },
        initGrid: function () {
            $('#gridtable').jfGrid({
                url: config.base_server() + 'cars/history?access_token=' + config.getToken().access_token,
                headData: [
                    {label: '车牌号', name: 'licensePlateNumber', width: 100, align: 'center'},
                    {label: '品牌', name: 'brand', width: 100, align: 'center'},
                    {label: '类型', name: 'type', width: 80, align: 'center'},
                    {label: '型号', name: 'serial', width: 150, align: 'left'},
                    {label: '颜色', name: 'color', width: 60, align: 'center'},
                    {label: '申请人', name: 'username', width: 80, align: 'center'},
                    {label: '驾驶员', name: 'driverName', width: 80, align: 'center'},
                    {label: '外出前里程', name: 'startMileage', width: 100, align: 'right'},
                    {
                        label: '借出时间', name: 'startTime', width: 160, align: 'center',
                        formatter: function (value) {
                            return learun.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
                        }
                    },
                    {
                        label: '回车时间', name: 'actureBackTime', width: 160, align: 'center',
                        formatter: function (value) {
                            return learun.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
                        }
                    },
                    {label: '回车里程', name: 'endMileage', width: 100, align: 'right'},
                    {
                        label: "", name: "btn1", width: 50, align: "left",
                        formatter: function (value, row, op, $cell) {
                            $cell.on('click', function () {
                                if ($cell.html().trim() == '') {
                                    return false;
                                }
                                var processId = $($cell[0].innerHTML).attr("data-value");
                                if (config.isTabs()) { //主题1
                                    learun.frameTab.open({
                                        id: processId,
                                        css: 'fa magic',
                                        name: '查看流程单',
                                        path:  config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?tabIframeId=' + processId + '&type=100' + "&processId=" + processId + "&taskId=" + '&access_token=' + config.getToken().access_token
                                    });
                                } else {
                                    learun.layerForm({
                                        id: processId,
                                        title: '查看流程单',
                                        url:   config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?tabIframeId=' + processId + '&type=100' + "&processId=" + processId + "&taskId=" + '&access_token=' + config.getToken().access_token,
                                        height: 1080,
                                        width: 1920
                                    });
                                }

                                return false;
                            });
                            return '<span class=\"label label-info\" data-value="' + row.processId + '" style=\"cursor: pointer;\">查看流程单</span>';
                        }
                    }
                ],

                isPage: true,
                reloadSelected: true,
                mainId: 'id'
            });

            page.search();
        },
        search: function (param) {
            param = param || {};
            $('#gridtable').jfGridSet('reload', param);
        }
    };

    refreshGirdData = function () {
        page.search();
    };

    page.init();
}


